#!/bin/bash
#ndk路径
NDK=/Users/luckylee/Library/Android/sdk/ndk/21.4.7075529
# 编译工具链目录
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64
# api 21 android 5
API=21



echo "进入FFmpeg编译脚本"
function build_android
{
echo "Compiling FFmpeg for $CPU"
./configure \
    --prefix=$PREFIX \
    --libdir=$LIB_DIR \
    --enable-shared \
    --disable-static \
    --enable-jni \
    --disable-doc \
    --disable-symver \
    --disable-programs \
    --target-os=android \
    --arch=$ARCH \
    --cpu=$CPU \
    --cc=$CC \
    --cxx=$CXX \
    --enable-cross-compile \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
    --disable-asm \
    $COMMON_FF_CFG_FLAGS
make clean
make -j8 # 这里是定义用几个CPU编译
make install
echo "The Compilation of FFmpeg for $CPU is completed"
}
#################### armv7-a ################################
 
echo "开始编译FFmpeg(armeabi-v7a)"

#source "config-env.sh"
source "build_ffmpeg_env.sh"

OUTPUT_FOLDER="armeabi-v7a"

ARCH="arm"

CPU="armv7-a"

TOOL_CPU_NAME=armv7a

TOOL_PREFIX="$TOOLCHAIN/bin/arm-linux-androideabi"
 
CC="$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang"
CXX="$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++"
#交叉编译环境目录
SYSROOT="$NDK/toolchains/llvm/prebuilt/darwin-x86_64/sysroot"

PREFIX="${PWD}/android/$OUTPUT_FOLDER"

LIB_DIR="${PWD}/android/libs/$OUTPUT_FOLDER"

OPTIMIZE_CFLAGS="-march=$CPU"
build_android





